﻿function getInfo(_0xd93dx2) {
    ajax('/shop/shopCategoryList/' + _0xd93dx2, {}, function (_0xd93dx3) {
        if (_0xd93dx3 != null) {
            loadgetdata(_0xd93dx3)
        }
    }, true, '', 'get')
}
function loadgetdata(_0xd93dx5) {
    var _0xd93dx6 = '';
    var _0xd93dx7 = '';
    var _0xd93dx8 = '';
    var _0xd93dx9 = $('.table-responsive #mytable tbody');
    if (_0xd93dx9['children']('tr')['length'] > 0) {
        n = _0xd93dx9['children']('tr')['length']
    } else {
        n = 0
    };
    for (var _0xd93dxa = 0; _0xd93dxa < _0xd93dx5['length']; _0xd93dxa++) {
        var _0xd93dxb = {};
        _0xd93dxb['ids'] = n;
        _0xd93dxb['Id'] = _0xd93dx5[_0xd93dxa]['Id'];
        _0xd93dxb['TypeId'] = _0xd93dx5[_0xd93dxa]['TypeId'];
        _0xd93dxb['CategoryOneId'] = _0xd93dx5[_0xd93dxa]['CategoryOneId'] == 0 ? _0xd93dx5[_0xd93dxa]['CategoryTwoId'] : _0xd93dx5[_0xd93dxa]['CategoryOneId'];
        _0xd93dxb['CategoryTwoId'] = _0xd93dx5[_0xd93dxa]['CategoryTwoId'];
        _0xd93dxb['onename'] = '';
        _0xd93dxb['twoname'] = _0xd93dx5[_0xd93dxa]['CategoryOneName'] == null ? _0xd93dx5[_0xd93dxa]['CategoryTwoName'] : _0xd93dx5[_0xd93dxa]['CategoryOneName'];
        _0xd93dxb['threename'] = _0xd93dx5[_0xd93dxa]['CategoryOneName'] == null ? '' : _0xd93dx5[_0xd93dxa]['CategoryTwoName'];
        if (_0xd93dx5[_0xd93dxa]['TypeId'] == 1) {
            _0xd93dxb['onename'] = '普通商品'
        } else {
            if (_0xd93dx5[_0xd93dxa]['TypeId'] == 2) {
                _0xd93dxb['onename'] = '合力免单商品'
            } else {
                if (_0xd93dx5[_0xd93dxa]['TypeId'] == 3) {
                    _0xd93dxb['onename'] = '趣卡专享商品'
                } else {
                    if (_0xd93dx5[_0xd93dxa]['TypeId'] == 4) {
                        _0xd93dxb['onename'] = '1元购商品'
                    }
                }
            }
        };
        dataAll['push'](_0xd93dxb);
        _0xd93dx9['append']('<tr id=\'n' + n + '\'>' + '<td>' + '<input class=\'form-control input1\' disabled=\'disabled\' type=\'text\' value=\'' + _0xd93dxb['onename'] + '\' />' + '</td>' + '<td>' + '<input type=\'text\' class=\'form-control input1\' disabled=\'disabled\' value=\'' + _0xd93dxb['twoname'] + '\' />' + '</td>' + '<td>' + '<input  type=\'text\' class=\'form-control\' disabled=\'disabled\' value=\'' + _0xd93dxb['threename'] + '\'/>' + '</td>' + '<td>' + '<button class=\'cancel\' id=\'' + n + '\'>' + '<span class=\'glyphicon glyphicon-remove\' >' + '</span>' + '</button>' + '</td>' + '</tr>');
        n++
    }
}
var dataAll = [];
var addList = [];
var delList = [];
var n = 0;
$('#addTables')['click'](function () {
    var _0xd93dx10 = '';
    if ($('#gc_id2')['find']('option:selected')['text']() == undefined || $('#gc_id2')['find']('option:selected')['text']() == '请选择') {
        _0xd93dx10 = ''
    } else {
        _0xd93dx10 = $('#gc_id2')['find']('option:selected')['text']()
    };
    if (_0xd93dx10 == '') {
        layer['msg']('请选择二级类目！', {
            icon: 5,
            time: 2000
        });
        return false
    };
    var _0xd93dx11 = false;
    var _0xd93dx12 = '';
    if ($('#gc_id1')['find']('option:selected')['text']() == '' || $('#gc_id1')['find']('option:selected')['text']() == '请选择') {
        _0xd93dx12 = ' '
    } else {
        _0xd93dx12 = $('#gc_id1')['find']('option:selected')['text']()
    };
    var _0xd93dx13 = $('#Shop_category')['find']('option:selected')['text']();
    if (dataAll != '') {
        for (var _0xd93dx14 = 0; _0xd93dx14 < dataAll['length']; _0xd93dx14++) {
            if (dataAll[_0xd93dx14]['onename'] == _0xd93dx13 && dataAll[_0xd93dx14]['twoname'] == _0xd93dx12 && dataAll[_0xd93dx14]['threename'] == _0xd93dx10) {
                layer['msg']('已经存在了，请重新选择！', {
                    icon: 5,
                    time: 2000
                });
                return false;
                _0xd93dx11 = true
            }
        };
        if (_0xd93dx11 == true) {} else {
            getdata();
            _0xd93dx11 = false
        }
    } else {
        getdata()
    }
});

function getdata() {
    var _0xd93dx10 = '';
    var _0xd93dx6 = '';
    var _0xd93dx7 = '';
    var _0xd93dx8 = '';
    var _0xd93dx9 = $('.table-responsive #mytable tbody');
    var _0xd93dx16 = '';
    if ($('#gc_id2')['find']('option:selected')['text']() == undefined || $('#gc_id2')['find']('option:selected')['text']() == '请选择') {
        _0xd93dx10 = ' ';
        _0xd93dx6 = ' '
    } else {
        _0xd93dx10 = $('#gc_id2')['find']('option:selected')['text']();
        if ($('#gc_id2')['find']('option:selected')['val']() != '') {
            if ($('#gc_id2')['find']('option:selected')['val']() == undefined) {
                _0xd93dx6 = ''
            } else {
                _0xd93dx6 = $('#gc_id2')['find']('option:selected')['val']()
            }
        } else {
            _0xd93dx6 = ''
        }
    };
    var _0xd93dx13 = $('#Shop_category')['find']('option:selected')['text']();
    _0xd93dx8 = $('#Shop_category')['val']();
    if ($('#gc_id1')['find']('option:selected')['val']() != '') {
        _0xd93dx7 = $('#gc_id1')['find']('option:selected')['val']()
    } else {
        _0xd93dx7 = ''
    };
    var _0xd93dx12 = '';
    if ($('#gc_id1')['find']('option:selected')['text']() == '' || $('#gc_id1')['find']('option:selected')['text']() == '请选择') {
        _0xd93dx12 = ' '
    } else {
        _0xd93dx12 = $('#gc_id1')['find']('option:selected')['text']()
    };
    var _0xd93dxb = {};
    var _0xd93dx17 = {};
    _0xd93dx17['ids'] = n;
    _0xd93dx17['Id'] = 0;
    _0xd93dx17['TypeId'] = _0xd93dx8;
    _0xd93dx17['CategoryOneId'] = $['trim'](_0xd93dx7) == '' ? '0' : _0xd93dx7;
    _0xd93dx17['CategoryTwoId'] = $['trim'](_0xd93dx6) == '' ? '0' : _0xd93dx6;
    _0xd93dxb['ids'] = n;
    _0xd93dx17['Id'] = 0;
    _0xd93dxb['TypeId'] = _0xd93dx8;
    _0xd93dxb['CategoryOneId'] = $['trim'](_0xd93dx7) == '' ? '0' : _0xd93dx7;
    _0xd93dxb['CategoryTwoId'] = $['trim'](_0xd93dx6) == '' ? '0' : _0xd93dx6;
    _0xd93dxb['onename'] = _0xd93dx13;
    _0xd93dxb['twoname'] = _0xd93dx12;
    _0xd93dxb['threename'] = _0xd93dx10;
    dataAll['push'](_0xd93dxb);
    addList['push'](_0xd93dx17);
    console['log'](dataAll);
    console['log'](addList);
    _0xd93dx9['append']('<tr id=\'n' + n + '\'>' + '<td>' + '<input class=\'form-control input1\' disabled=\'disabled\' type=\'text\' value=\'' + _0xd93dx13 + '\' />' + '</td>' + '<td>' + '<input type=\'text\' class=\'form-control input1\' disabled=\'disabled\' value=\'' + _0xd93dx12 + '\' />' + '</td>' + '<td>' + '<input  type=\'text\' class=\'form-control\' disabled=\'disabled\' value=\'' + _0xd93dx10 + '\'/>' + '</td>' + '<td>' + '<button class=\'cancel\' id=\'' + n + '\'>' + '<span class=\'glyphicon glyphicon-remove\' >' + '</span>' + '</button>' + '</td>' + '</tr>');
    n++
}
$('#mytable')['on']('click', '.cancel', function () {
    var _0xd93dx2 = $(this)['attr']('id');
    for (var _0xd93dxa = 0; _0xd93dxa < dataAll['length']; _0xd93dxa++) {
        if (dataAll[_0xd93dxa]['ids'] == _0xd93dx2) {
            if (dataAll[_0xd93dxa]['id'] == 0) {
                for (var _0xd93dx14 = 0; _0xd93dx14 < addList['length']; _0xd93dx14++) {
                    if (addList[_0xd93dx14]['ids'] == _0xd93dx2) {
                        addList['splice'](_0xd93dx14, 1)
                    }
                }
            } else {
                delList['push'](dataAll[_0xd93dxa])
            };
            dataAll['splice'](_0xd93dxa, 1)
        }
    };
    var _0xd93dx18 = $(this)['parent']('td');
    var _0xd93dx19 = _0xd93dx18['parent']('tr');
    _0xd93dx19['remove']();
    console['log'](addList);
    console['log'](delList)
});

function getClass(_0xd93dx2, _0xd93dx1b, _0xd93dx1c) {
    if (_0xd93dx1c == 4) {
        _0xd93dx1c = 2
    };
    ajax('/tools/GetCategoryList/' + _0xd93dx2 + '/' + _0xd93dx1c, {}, function (_0xd93dx3) {
        var _0xd93dx1d = '<option value=\'\'>请选择</option>';
        $['each'](_0xd93dx3, function (_0xd93dx1e, _0xd93dx1f) {
            _0xd93dx1d += '<option value=\'' + _0xd93dx1f['id'] + '\'>' + _0xd93dx1f['name'] + '</option>'
        });
        $(_0xd93dx1b)['html'](_0xd93dx1d);
        $(_0xd93dx1b)['show']()
    })
}
$('#Shop_category')['change'](function () {
    var _0xd93dx20 = $('#Shop_category')['val']();
    if (_0xd93dx20 != '') {
        getClass(0, '#gc_id1', _0xd93dx20);
        $('#gc_id2')['html']('');
        $('#gc_id2')['hide']()
    } else {
        $('#gc_id1')['html']('<option  value=\'\'>请选择一级分类</option>')
    }
});
$('#gc_id1')['change'](function () {
    var _0xd93dx20 = $('#Shop_category')['val']();
    var _0xd93dx21 = $(this)['val']();
    if (_0xd93dx21 != '') {
        getClass(_0xd93dx21, '#gc_id2', _0xd93dx20)
    } else {
        $('#gc_id2')['html']('<option value=\'\'>请选择二级分类</option>')
    }
});
$('#btnSave')['click'](function () {
    if (addList['length'] > 0 || delList['length'] > 0) {
        ajax('/shop/SaveshopCategory/', {
            id: _id,
            addList: addList,
            delList: delList
        }, function (_0xd93dx3) {
            if (_0xd93dx3['status'] == 'y') {
                layer['msg']('操作成功', {
                    icon: 6,
                    time: 1200
                }, function () {
                    window['location']['href'] = '/shop/store'
                })
            } else {
                layer['msg'](_0xd93dx3['info'], {
                    icon: 5,
                    time: 2000
                })
            }
        })
    } else {
        layer['msg']('未做任何更改！', {
            icon: 5,
            time: 2000
        })
    }
})